(function () {
    //<editor-fold desc="helper">
    var getFnName = function(fn) {
        var funcNameRegex = /function (.{1,})\(/;
        var results = (funcNameRegex).exec(fn.toString());
        return (results && results.length > 1) ? results[1] : "";
    }

    var log = function (s) {
        var out = document.getElementById('log_output');
        if (!out) {
            out = document.createElement('div');
            out.id = 'log_output';
            document.body.appendChild(out);
        }
        var msg = document.createElement('div');
        msg.innerHTML = s;
        out.appendChild(msg);
    };
    var eq = function (actual, expected) {
        if (actual !== expected) {
            log('assertion failed - expected: <span class="expected">' + expected + '</span>, actual: <span class="actual">' + actual + '</span>');
        }
    };
    var is = function (obj, clazz) {
        if (!(obj instanceof clazz)) {
            log('assertion failed - expected: <span class="expected">' + getFnName(clazz) + '</span>, actual: <span class="actual">' + getFnName(obj.constructor) + '</span>');
        }
    };
    //</editor-fold>

    try {
        var plan = new Plan(plan_data);
        is(plan, Plan);
        eq(plan.planProjects.length, 2);
        log('<span class="hint">**** all done ****</span>');
    } catch (e) {
        log('<spaln class="error">ERROR: </spaln>' + e.toString());
    }
})();
